/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bl;

import entity.Employee;
import java.util.ArrayList;
import java.util.Date;
import javax.swing.JLabel;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Kien Chinh
 */
public class ModelTableReportManager extends AbstractTableModel{
    private final static int STT = 0;
    private final static int NAME = 1;
    private final static int ORGANIZATION = 2;
    private final static int DEPARTMENT = 3;
    private final static int TOTAL = 4;
    private final static int SHOW = 5;
    
    ArrayList<Employee> list;
    
    private String[] columnName = {"No.","Full Name","Organization","Department","Total leave","#"};
    private String year;
    private EmployeeBusiness business;

    public ModelTableReportManager(ArrayList<Employee> list,String year) {
        this.list = list;
        this.year = year;
        business = new EmployeeBusiness();
    }

    @Override
    public int getRowCount() {
        return list.size();
    }

    @Override
    public int getColumnCount() {
        return columnName.length;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Employee e = list.get(rowIndex);
        switch(columnIndex){
            case STT :
                return rowIndex+1;
            case NAME :
                return e.getFullName();
            case ORGANIZATION :
                return e.getOrganization().getName();
            case DEPARTMENT :
                return e.getDepartment().getName();
            case TOTAL :
                return business.countLeaveDetail(e, year);
            case SHOW :
                return new JLabel("                          Detail");
            default :
                return new Object();
        }
    }
    
    @Override
    public Class getColumnClass(int columnIndex) {
        switch (columnIndex) {
            case STT:
                return Integer.class;
            case NAME:
                return String.class;
            case DEPARTMENT:
                return String.class;
            case ORGANIZATION:
                return String.class;
            case TOTAL:
                return Integer.class;
            case SHOW:
                return JLabel.class;
            default:
                return Object.class;
        }
    }
    
    @Override
    public String getColumnName(int columnIndex) {
        return columnName[columnIndex];
    }

    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
        return false;
    }
}
